package com.duiba.controller;

import cn.com.duiba.goods.center.api.remoteservice.dto.item.ItemDescConfigDto;
import cn.com.duiba.goods.center.api.remoteservice.dto.item.ItemKeyDto;
import cn.com.duiba.goods.center.api.remoteservice.item.RemoteItemDescConfigService;
import cn.com.duiba.goods.center.api.remoteservice.item.RemoteItemKeyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TestController {

    public static Logger log = LoggerFactory.getLogger(TestController.class);

    @Resource
    private RemoteItemDescConfigService remoteItemDescConfigService;

    @Resource
    private RemoteItemKeyService remoteItemKeyService;


    @RequestMapping("/test")
    public String test(@RequestParam Long itemId) {
        ItemDescConfigDto itemDescConfigDto = remoteItemDescConfigService.findByItemId(itemId);
        return itemDescConfigDto.getMultiImage();
    }

    @RequestMapping("/test2")
    public Object test2(@RequestParam Long itemId) {
        ItemKeyDto itemKeyDto = remoteItemKeyService.findItemKeyNew(null, itemId, null);
        return itemKeyDto.getItem();
    }

    @RequestMapping("/testThreadPool")
    public void testThreadPool() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.initialize();
        executor.execute(()->{
            try {
                long sum = 0;
                for (long i = 0; i < 1200000000; i++) {
                    sum += i;
                }
                log.info("执行完成 result={}",sum);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
        executor.shutdown();
    }
}
